package mk.jug.academy.dao;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import mk.jug.academy.model.Administrator;

/**
 * DAO regarding the {@link Administrator} model entity.
 *
 * @author Ice.Penov
 */
@Repository
public class AdministratorDAO extends GenericDAO<Administrator> {
	
	/**
	 * Finds an {@link Administrator} with the supplied email.
	 */
	public Administrator findByEmail(final String email) {
		return new QueryEMContext<Administrator>() {
			public Administrator query(EntityManager em) {
				Query query = em.createQuery("Select admin from Administrator admin where admin.email = :email");
				query.setParameter("email", email);
				return (Administrator) query.getSingleResult();
			}
		}.result();
	}
	
}